package com.dd.logistics.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dd.logistics.entity.InventoryHistory;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface InventoryHistoryMapper extends BaseMapper<InventoryHistory> {
    
    @Select("SELECT h.* FROM inventory_history h " +
            "LEFT JOIN inventory i ON h.inventory_id = i.id " +
            "LEFT JOIN supplier_product sp ON i.product_id = sp.id " +
            "WHERE sp.product_code = #{productCode} " +
            "AND (#{startDate} = '' OR h.create_time >= #{startDate}) " +
            "AND (#{endDate} = '' OR h.create_time <= #{endDate}) " +
            "ORDER BY h.create_time DESC")
    List<InventoryHistory> selectHistoryList(
            @Param("productCode") String productCode,
            @Param("startDate") String startDate,
            @Param("endDate") String endDate);
} 